#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct TreeNode {
  int val;
  TreeNode *left;
  TreeNode *right;
  TreeNode() : val(0), left(nullptr), right(nullptr) {}
  TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
  TreeNode(int x, TreeNode *left, TreeNode *right)
      : val(x), left(left), right(right) {}
};

class Solution {
public:
  vector<vector<int>> levelOrder(TreeNode *root) {
    vector<vector<int>> vv;
    if (!root)
      return vv;
    queue<TreeNode *> q;
    q.push(root);
    int len;
    while (!q.empty()) {
      vector<int> v;
      len = q.size();
      for (int i = 0; i < len; ++i) {
        TreeNode *head = q.front();
        q.pop();
        if (head->left)
          q.push(head->left);
        if (head->right)
          q.push(head->right);
        v.push_back(head->val);
      }
      vv.push_back(v);
    }
    return vv;
  }
};
int main() { return 0; }